package gui;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;

import org.Globals;

import CustomUI.ydCustomColorPicker;
import DTO.GradientsDTO;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.Formatter;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.RelativeLayout;

import com.ydev.graphics.animations.R;

public class Home extends Activity {
	
	ydCustomColorPicker ydCCP;
	ArrayList<GradientsDTO> grads=new ArrayList<GradientsDTO>();
	
	RelativeLayout RR;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        
        Globals.initialize(this);
        
        Log.d("IP", getLocalIpAddress());
        
        //grads=GradientsDTO.getObjectsInDatabase(Globals.sqlDB);
        RR=(RelativeLayout)findViewById(R.id.RR);
        
       /* Timer t = new Timer();
      //Set the schedule function and rate
        Activity act=this;
      t.scheduleAtFixedRate(new TimerTask() {
    	  int i=0;
          @Override
          public void run() {
        	  GradientsDTO g;
        	  g=grads.get(i);
        	  RR.setBackground(Utility.byteArrayToDrawable(Utility.bitmaptoByteArray(g.image)));
        	  i++;
          }
               
      },
      //Set how long before to start calling the TimerTask (in milliseconds)
      0,
      //Set the amount of time between each execution (in milliseconds)
      1000);*/
/*        ydCCP= new ydCustomColorPicker(this);
        runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				ydCCP.show();
				
			}
		});*/
       
       /* Intent intent = new Intent (Home.this,
        		ydCustomColorPickerActivity.class);
			startActivity(intent);*/
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }
    
    public String getLocalIpAddress() {
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {
                        String ip = Formatter.formatIpAddress(inetAddress.hashCode());
                        Log.i("IP", "***** IP="+ ip);
                        return ip;
                    }
                }
            }
        } catch (SocketException ex) {
            Log.e("IP", ex.toString());
        }
        return null;
    }
    
    public void objectsClicked(View v){
		Intent intent = new Intent (Home.this,
				Objects.class);
			startActivity(intent);
    }
    public void assembleClicked(View v){
    	Intent intent = new Intent (Home.this,
				Assemble.class);
			startActivity(intent);
    }
}
